package TrabalhoEda;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;

class DesenhaPontos
{
	private BufferedImage bufferedImage;
	private static final String fname = ("D:\\EDA13_14\\peppersgrad.bmp");
	private ImageIO image;
	private double maxValue = 255;
	private static int startX = 192;
	private static int startY = 48;
	private static int endX = 260;
	private static int endY = 508;
	private static int width = 512;
	private static int height = 512;
	private double[][] pixeis;

	public void run() throws IOException
	{

		this.loadImage(this.image);
		
		this.loadPixel();
	}

	@SuppressWarnings({ "static-access" })
	DesenhaPontos(int startX, int startY, int endX, int endY, ImageIO image)
	{
		this.startX = startX;
		this.startY = startY;
		this.endY = endY;
		this.endX = endX;
		this.image = image;

	}

	public void loadImage(ImageIO image) throws IOException 	
	{
		File file = new File(fname);
		
		bufferedImage = ImageIO.read(file);

		height = bufferedImage.getHeight();

		width = bufferedImage.getWidth();

		System.out.println(height + " " + width);

	}


	private void loadPixel() 
	{

		//this.pixeis = new double[width][height];
		
		this.pixeis = new double[height][width];

		for (int line = 0; line < height; line++)
		{

			for (int col = 0; col < width; col++)
			{
				int pix = (bufferedImage.getRGB(col, line));

				int b = pix & 0xFF;
				
				//pixeis[col][line] = 1.0 - ((double) b / maxValue);
				
				pixeis[line][col] = 1.0 - ((double) b / maxValue);
				
				
				
			}
		}
		
		/*

		int pix = bufferedImage.getRGB(startX, startY);

		int b = pix & 0xFF;

		System.out.println("inicio " + b + " => " + pixeis[startX][startY]);

		pix = bufferedImage.getRGB(endX, endY);

		 b = pix & 0xFF;

		System.out.println("fim " + b + " => " + pixeis[endX][endY]);
		*/

		AStar astar = new AStar(this.pixeis);
		JFrame frame = new JFrame("TRABALHO DE EDA_13/14");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setResizable(true);
		frame.setLocationRelativeTo(null);
		ApresentarImage apresentarImage = new ApresentarImage(bufferedImage,
				astar.getlistaNosFechados());
		frame.add(apresentarImage);
		frame.setSize(width, height);
		frame.setVisible(true);

	}

}
